package com.guigu.eduservice.controller;

import com.guigu.common.utils.R;
import com.guigu.eduservice.dto.BusinessmanEquipmentDto;
import com.guigu.eduservice.entity.BusinessmanEquipment;
import com.guigu.eduservice.service.BusinessmanEquipmentService;
import com.guigu.eduservice.utils.EmployeeJwtUtils;
import com.guigu.eduservice.vo.BusinessmanVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/eduservice/businessmanEquipment")
public class BusinessmanEquipmentController {

    @Autowired
    private BusinessmanEquipmentService businessmanEquipmentService;
    /**
     * (评估师)检测任务(返回所有检测任务)
     *
     * @param request token的业务员id
     * @return 检测任务列表
     */
    @GetMapping ("/getTaskList")
    public R getTaskList(HttpServletRequest request) {
        int businessmanId = EmployeeJwtUtils.getUserIDByJwtToken(request);
        List<BusinessmanEquipmentDto> taskList = businessmanEquipmentService.getTaskList(businessmanId);
        return R.ok().data("taskList", taskList);
    }

    // await httpInstance.post(`/eduservice/equipment/allocate/${currentAllocateEquipment.value.equipmentId}`, {
    //   businessmanId: businessman.id,
    // });
    @PostMapping("/allocate/{equipmentId}")
    public boolean allocate(@PathVariable Long equipmentId,@RequestBody BusinessmanVo vo) {
        return businessmanEquipmentService.allocateEquipment(equipmentId, vo);
    }

    @GetMapping("/getBusinessmanById/{equipmentId}")
    public BusinessmanEquipment getBusinessmanById(@PathVariable Long equipmentId) {
        return businessmanEquipmentService.getBusinessmanEquipment(equipmentId);
    }
}
